import React, { Component } from 'react'
import {ListBox} from '../../../components'
import UpdateProModelPage from './UpdateNew'

// import {fetchData} from '../../../components/AjaxConsumer'
import {  Button, Modal, Form, Input, Radio,Upload, Icon } from 'antd';
export default class ListProModelPage extends Component {
    constructor(props) {
        super(props);
        this.state = {
            tableColumn: {},
            searchComponentData: [],
            visible: false,
        };
        //行操作列表
        this.rowOperation = [
            {
                handleName: 'edit',
                iconClass: 'cellEdit'
            }, {
                handleName: 'delete',
                iconClass: 'cellDele'
            }, {
                handleName: 'assignUser',
                iconClass: 'cellRole'
            }
        ];
        //header 操作列表
        this.headerOperation = [
            {
                handleName: 'add',
                showName: '新增',
                iconClass: 'plus',
                // permission: 'rawbarcode-add'
            },{
                handleName: 'edit',
                showName: '修改',
                iconClass: 'edit',
                // permission: 'rawbarcode-edit'
            }
            ,{
                handleName: 'delete',
                showName: '删除',
                iconClass: 'delete',
                // permission: 'rawbarcode-del'
            }
        ];
        //table列表展示列配置
        //showName、columnName 必有属性， columnWidth 可选，默认100, columnHidden: true 列隐藏
        this.tableColumn = {
            storageKey: 'modelId',
            data: [
                {
                    showName: 'modelId',
                    columnName: 'modelId',
                    columnHidden:true,
                    foreverHidden: true
                },{
                    showName: '型号',
                    columnName: 'model'
                },
                {
                    showName: '品名',
                    columnName: 'productName'
                },
                {
                    showName: '定量',
                    columnName: 'density'
                },
                {
                    showName: '规格',
                    columnName: 'spec'
                },{
                    showName: '计量单位',
                    columnName: 'unit'
                }, {
                    showName: '生产机器号',
                    columnName: 'machineNumber',
                    showOption:[
                        {
                            optionKey:'2',
                            optionShow:"2号机"
                        },{
                            optionKey:'4',
                            optionShow:"4号机"
                        }
                    ]
                }, {
                    showName: '创建人',
                    columnName: 'createBy'
                }, {
                    showName: '创建时间',
                    columnName: 'gmtCreate'
                }, {
                    showName: '最后修改人',
                    columnName: 'lastModifiedBy'
                }, {
                    showName: '最后修改时间',
                    columnName: 'gmtModified'
                }
            ]
        };

        //搜索属性配置
        this.searchComponentData = [
            {
                showName: '计量单位',
                name: 'unit',
                type: 'select',
                url:'/base/dic/get/unit'
            },
            {
                showName: '生产机器号',
                name: 'machineNumber',
                type: 'select',
                url:'/base/dic/get/machine_number'
            },
            {
                showName:'创建时间',
                name:'gmtCreate',
                type: 'date',
                maxName:'gmtCreateMax',
                minName:'gmtCreateMin'
            },
            {
                showName:'最后修改时间',
                name:'gmtModified',
                type: 'date',
                maxName:'gmtModifiedMax',
                minName:'gmtModifiedMin'
            }
        ];

    }

    rowHandles = (strHandles, rowObj) => {
        console.log("strHandles===ListResource=======", strHandles);
        if (strHandles === 'edit') {
            this.editHandle(rowObj);
        } else if (strHandles === 'delete') {
            this.deleteHandle(rowObj);
        } else if (strHandles === 'add') {
            this.addHandle();
        } else if (strHandles == 'upload') {
            this.upload();
        }
    }
    // 新增成品类型
    addHandle = () => {
        console.log("====执行了新增成品类型操作====");
        this.refs.updateProModel.addProModelHandle();
    }

    // // 上传
    // upload = () => {
    //     console.log("====执行了上传操作====");
    //             //    this.setState({ visible: true });
    //     this.refs.updateProModelUp.add();
                


    // }
    editHandle = (rowObj) => {
        if(rowObj.length == 0){
            Modal.error({
                title: '错误提示',
                content: '请选择一条数据',
            });
        }else if(rowObj.length > 1){
            Modal.error({
                title: '错误提示',
                content: '只能选择一条数据',
            });
        }else{
            this.refs.updateProModel.editHandle(rowObj[0].data);
        }
    }

    deleteHandle = (rowObj) => {
        if(rowObj.length == 0){
            Modal.error({
                title: '错误提示',
                content: '请选择一条数据',
            });
        }else if(rowObj.length > 1){
            Modal.error({
                title: '错误提示',
                content: '只能选择一条数据',
            });
        }else{
            this.refs.updateProModel.deleteHandle(rowObj[0].data)
        }
    }
    // 给区域分配角色
    // assignFactoryUserHandle = (rowObj) => {
    //     let workareaId = rowObj.workareaId;
    //     this.refs.assignFactoryUser.initModal(workareaId);
    // }


    //刷新列表
    refreshHandle = () => {
        this.refs.listProModel.refreshHandle();
    }

    // componentWillMount() {
    //     const dicType = 'model_type';
    //     const options= {
    //         url: '/base/dic/get/' + dicType,
    //         type: 'get',
    //         condition:{}
    //     };
    //     //先写死，后面再改
    //     fetchData(this, options, this.dicInitCallBackHandle);
    //     console.log("====执行了1====");
    //     const dicType1 = 'unit_length';
    //     const options1= {
    //         url: '/base/dic/get/' + dicType1,
    //         type: 'get',
    //         condition:{}
    //     };
    //     //先写死，后面再改
    //     fetchData(this, options1, this.dicInitCallBackHandle1);
    //     console.log("====执行了2====");
    // }

    //下拉框 初始化
    // dicInitCallBackHandle = (resData)=>{
    //     //alert('resData' + JSON.stringify(resData, null, 4));
    //     let optionList = [];
    //     let tmp = {};
    //     tmp.optionKey = '';
    //     tmp.optionShow = '';
    //     optionList.push(tmp);
    //     resData.data.map( (e,index) => {
    //         let tmp = {};
    //         tmp.optionKey = e.dicCode;
    //         tmp.optionShow = e.dicName;
    //         optionList.push(tmp);
    //     });

    //     //alert('optionList' + JSON.stringify(optionList, null, 4));
    //     this.tableColumn.data[2].showOption = optionList;
    //     this.searchComponentData[0].optionList = optionList;
    //     //this.setState({
    //     //    tableColumn: this.tableColumn,
    //     //    searchComponentData: this.searchComponentData
    //     //})

    // }

    // //下拉框 初始化
    // dicInitCallBackHandle1 = (resData)=>{
    //     //alert('resData' + JSON.stringify(resData, null, 4));
    //     let optionList = [];
    //     let tmp = {};
    //     tmp.optionKey = '';
    //     tmp.optionShow = '';
    //     optionList.push(tmp);
    //     resData.data.map( (e,index) => {
    //         let tmp = {};
    //         tmp.optionKey = e.dicCode;
    //         tmp.optionShow = e.dicName;
    //         optionList.push(tmp);
    //     });

    //     //alert('optionList' + JSON.stringify(optionList, null, 4));
    //     this.tableColumn.data[6].showOption = optionList;
    //     this.searchComponentData[1].optionList = optionList;
    //     console.log("====执行了3====");
    //     //this.setState({
    //     //    tableColumn: this.tableColumn,
    //     //    searchComponentData: this.searchComponentData
    //     //})

    // }

//   handleCancel = () => {
//     this.setState({ visible: false });
//       this.form.resetFields();
    
//   }
//   handleCreate = () => {
//     const form = this.form;
//     form.validateFields((err, values) => {
//       if (err) {
//         return;
//       }

//       console.log('Received values of form: ', values);
//       form.resetFields();
//       this.setState({ visible: false });
//     });
//   }
//   saveFormRef = (form) => {
//     this.form = form;
//   }


    render() {
        //当左侧隐藏时，列表宽度加上左侧的宽度，
        //1、当前this.props.isHideLeft 是从页面组件containers/Main/main.js传过来
        //2、this.props.isHideLeft 最顶级赋值是在页面 containers/Main/main.js
        let isHideLeft = this.props.isHideLeft;

        return (
            <div>
                <ListBox
                    ref='listProModel'
                    title="成品型号"
                    isHideLeft={isHideLeft}
                    tableColumnData={this.tableColumn}
                    searchComponentData={this.searchComponentData}
                    url='/base/promodel/list'
                    rowHandles={this.rowHandles}
                    rowOperation={this.rowOperation}
                    headerOperation={this.headerOperation}
                    isRowSingle = "true"
                />

                <UpdateProModelPage
                    ref="updateProModel"
                    refreshHandle={this.refreshHandle}
                />

            </div>
        )
    }
}
